package org.nf.trading.controller.app.product;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nf.trading.controller.BaseController;
import org.nf.trading.entity.Favorite;
import org.nf.trading.service.app.product.FavoriteService;
import org.nf.trading.vo.ResultVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/api/favorite")
@CrossOrigin
public class FavoriteController extends BaseController {
    private final FavoriteService favoriteService;

    /**
     * 查询用户收藏的数量
     * @param uid
     * @return
     */
    @GetMapping("/count/{uid}")
    public ResultVO countFavoritesByUid(@PathVariable("uid") Integer uid){
        Long l = favoriteService.countByUId(uid);
        return success(l);
    }

    @GetMapping("/uid/{uid}")
    public ResultVO getListFavoritesByUid(@PathVariable("uid") Integer uid){
        List<Favorite> favorites = favoriteService.listFavoritesByUid(uid);
        return success(favorites);
    }
    /**
     * 收藏商品
     * @param favorite
     * @return
     */
    @PostMapping
    public ResultVO insert(Favorite favorite){
        boolean row = favoriteService.insert(favorite);
        return success(200,"收藏成功",row);
    }

}
